package com.example.oversea_home_spring.controller;

import com.example.oversea_home_spring.bean.Warehouse;
import com.example.oversea_home_spring.service.AdminiService;
import com.example.oversea_home_spring.uitl.CodeMsg;
import com.example.oversea_home_spring.uitl.DateUtil;
import com.example.oversea_home_spring.uitl.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin//跨域
@RequestMapping("admini")
public class AdminiControler {

    @Autowired
    AdminiService adminiService;

    //仓库申请情况
    @GetMapping("allHouse")
    public Result<List<Warehouse>> selectAllHouse(){
        List<Warehouse> list = adminiService.selectAllHouse();
        if(list != null){
            return Result.success(list);
        }
        return Result.error(CodeMsg.HOUSE_ALL_ERROR);
    }


    //处理操作
    @PutMapping("updateHouseStatue")
    public Result<Integer> updateOneHouse(Warehouse warehouse){
        warehouse.setUpdate_time(DateUtil.myDate());
        int isOk = adminiService.updateOneHouse(warehouse);
        if(isOk > 0){
            return Result.success(isOk);
        }
        return Result.error(CodeMsg.HOUSE_STATUS_ERROR);
    }

}
